package com.badibadi.activity;

import java.util.HashMap;
import java.util.Map;

import com.badibadi.infos.ExpertApplyChoseTypePictureInfos;
import com.badibadi.infos.ListsModel;
import com.badibadi.infos.MasterModel;
import com.badibadi.infos.PostActivity1ChoseTypeInfos;
import com.badibadi.infos.Results;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.JSONUtils;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.menu;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class PostActivity1Activity extends ExpertApplyForChoseTypeActivity {

	private String KEY = "PostActivity1Activity";
	private String cid;
	private ListsModel listsModel;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		try {
			cid = getIntent().getStringExtra("cid");
//			   
		} catch (Exception e) {
			// TODO: handle exception
		}
		init();
	}

	@Override
	protected void initItemNum(int num) {
		// TODO Auto-generated method stub
		num = new PostActivity1ChoseTypeInfos(PostActivity1Activity.this)
				.getItem().length;
		super.initItemNum(num);
	}

	// @Override
	// public void initData(String[] tupianming, String[] beijingtu) {
	// // TODO Auto-generated method stub
	// PostActivity1ChoseTypeInfos experInfos = new PostActivity1ChoseTypeInfos(
	// this);
	// tupianming = experInfos.getItem();
	// beijingtu = experInfos.getPic();
	// }

	/**
	 * 重写四处 复用的话重写它（第一处） 要重写它
	 */
	protected void initInterNet() {
		// TODO Auto-generated method stub
		Utils.showPrgress(PostActivity1Activity.this);
		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				listsModel = new ListsModel();
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("type", "huodong");
				map.put("languageType", com.badibadi.mytools.Dialog
						.getSystemLanguageType(PostActivity1Activity.this));
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "type/all_type");
				//    
				if (content != null) {
					//    
					Results results = Utils.checkResult_NNN(
							PostActivity1Activity.this, content);
					if (results != null && results.getRetmsg() != null) {
//						   
						try {
							listsModel = JSONUtils.getEntityByJsonString(
									results.getRetmsg(), ListsModel.class);
							if (listsModel.getLists() != null
									&& !listsModel.getLists().isEmpty()) {
								for (int i = 0; i < listsModel.getLists()
										.size(); i++) {
									MasterModel masterModel = new MasterModel();
									masterModel.setId(listsModel.getLists()
											.get(i).getId());
									masterModel.setName(listsModel.getLists()
											.get(i).getName());
									masterListView.add(masterModel);
								}
							}
							for (int i = 0; i < masterListView.size(); i++) {
								list.add(masterListView.get(i).getName());
							}
							ItemNum = masterListView.size();
							mHandler.sendEmptyMessage(0);

						} catch (Exception e) {
							// TODO Auto-generated catch block
//							   
							   
						}
					}
				} else {
					Utils.ExitPrgress(PostActivity1Activity.this);
					mHandler.sendEmptyMessage(1);
				}
			}
		}).start();

	}

	private void init() {
		TextView tv = (TextView) this
				.findViewById(R.id.expert_appley_for_chose_type_title);
		tv.setText(R.string.PostActivity);
		TextView tv1 = (TextView) this
				.findViewById(R.id.expert_appley_for_chose_club_type);
		tv1.setText(R.string.ChoseActivityType);
		this.findViewById(R.id.next_step).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						String data = GetDataId();
						if (data != null || data != "") {
							Intent intent = new Intent(
									PostActivity1Activity.this,
									PostActivity2Activity.class);
							intent.putExtra(KEY, "" + data);
							intent.putExtra("cid", cid);
							startActivity(intent);
							finish();
							overridePendingTransition(R.anim.slide_left,
									R.anim.slide_right);

						} else {
							ShowToast(
									PostActivity1Activity.this,
									""
											+ getResources()
													.getString(
															R.string.PleaseChoseActivityType));
						}
					}
				});
	}

}
